<?

function newTeam($data) {
    $array = array();

    $title = $data['team'];

    // Create post object
    $postOptions = array(
        'post_title' => $title,
        'post_type' => 'team',
        'post_status' => 'publish',
        'post_author' => 1,
    );

    // Insert the post into the database
    $post_id = wp_insert_post($postOptions, $wp_error);

    update_field('field_51ab3c36e1cf5', $data['name'], $post_id);
    update_field('field_51ab3c45e1cf6', get_user_id(), $post_id); //user
    update_field('field_51ab3c55e1cf7', $data['colour'], $post_id);
    update_field('field_51ab3c5fe1cf8', $data['players'], $post_id);

    $array['status'] = 'added team id = ' . $post_id . ' name = ' . $data['name'];
    $array['post'] = $post_id;
    $array['options'] = $data;
    $array['error'] = $wp_error;

    return $array;


}